package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.IReceiveOrBackPatrolOrderView;
import com.cloudsigns.factorymanager2.engineering.model.IReceiveOrBackPatrolOrderModel;
import com.cloudsigns.factorymanager2.engineering.model.ReceiveOrBackPatrolOrderModel;

/**
 * Created by tony on 2018/5/27.
 */

public class ReceiveOrBackPatrolOrderPresenter {
    private IReceiveOrBackPatrolOrderView view;
    private IReceiveOrBackPatrolOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public ReceiveOrBackPatrolOrderPresenter(IReceiveOrBackPatrolOrderView view) {
        this.view = view;
        this.model = new ReceiveOrBackPatrolOrderModel();
    }

    public void receiveOrBackPatrolOrder() {


        model.receiveOrBackPatrolOrder(view.getAssignReceiveOrderId(), view.getOrderId(), view.getStatus(), new ReceiveOrBackPatrolOrderModel.OnReceiveOrBackPatrolOrderListener() {
            @Override
            public void receiveOrderSuccessed() {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.receiveOrBackOrderSuccessed();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.receiveOrBackOrderFailed(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
